package org.jing.core.logger;

import org.jing.core.lang.JingInitializer;
import org.jing.core.logger.itf.JingLoggerFactoryItf;
import org.jing.core.logger.itf.JingLoggerItf;
import org.jing.core.logger.itf.JingLoggerLevelItf;

import java.util.Hashtable;

/**
 * Description: <br>
 *
 * @author bks <br>
 * @since 2021-08-16 <br>
 */
@SuppressWarnings("unused")
public class JingLogger {
    private static JingLoggerFactoryItf factory;

    private static final Hashtable<String, JingLogger> repository = new Hashtable<>();

    private final JingLoggerItf itf;

    synchronized static void setFactory(JingLoggerFactoryItf factory) {
        JingLogger.factory = factory;
    }

    public synchronized static JingLogger getLogger(String name, boolean remake) {
        JingInitializer.getInstance(JingLoggerInitializer.class);
        JingLogger logger;
        JingLoggerItf itf;
        if (remake || null == (logger = repository.get(name))) {
            itf = factory.getLogger(name);
            repository.put(name, (logger = new JingLogger(itf)));
        }
        return logger;
    }

    public static JingLogger getLogger(String name) {
        return getLogger(name, false);
    }

    public static JingLogger getLogger(Class clazz, boolean remake) {
        String name = clazz.getName();
        return getLogger(name, remake);
    }

    public static JingLogger getLogger(Class clazz) {
        String name = clazz.getName();
        return getLogger(name, false);
    }

    private JingLogger(JingLoggerItf itf) {
        this.itf = itf;
    }

    public void all(Object object) {
        if (factory.isAllEnable()) itf.all(object);
    }

    public void all(Throwable throwable) {
        if (factory.isAllEnable()) itf.all(throwable);
    }

    public void all(String msg, Object... parameters) {
        if (factory.isAllEnable()) itf.all(msg, parameters);
    }

    public void all(Throwable throwable, String msg) {
        if (factory.isAllEnable()) itf.all(throwable, msg);
    }

    public void all(Throwable throwable, String msg, Object... parameters) {
        if (factory.isAllEnable()) itf.all(throwable, msg, parameters);
    }

    public void trace(Object object) {
        if (factory.isTraceEnable()) itf.trace(object);
    }

    public void trace(Throwable throwable) {
        if (factory.isTraceEnable()) itf.trace(throwable);
    }

    public void trace(String msg, Object... parameters) {
        if (factory.isTraceEnable()) itf.trace(msg, parameters);
    }

    public void trace(Throwable throwable, String msg) {
        if (factory.isTraceEnable()) itf.trace(throwable, msg);
    }

    public void trace(Throwable throwable, String msg, Object... parameters) {
        if (factory.isTraceEnable()) itf.trace(throwable, msg, parameters);
    }

    public void debug(Object object) {
        if (factory.isDebugEnable()) itf.debug(object);
    }

    public void debug(Throwable throwable) {
        if (factory.isDebugEnable()) itf.debug(throwable);
    }

    public void debug(String msg, Object... parameters) {
        if (factory.isDebugEnable()) itf.debug(msg, parameters);
    }

    public void debug(Throwable throwable, String msg) {
        if (factory.isDebugEnable()) itf.debug(throwable, msg);
    }

    public void debug(Throwable throwable, String msg, Object... parameters) {
        if (factory.isDebugEnable()) itf.debug(throwable, msg, parameters);
    }

    public void info(Object object) {
        if (factory.isInfoEnable()) itf.info(object);
    }

    public void info(Throwable throwable) {
        if (factory.isInfoEnable()) itf.info(throwable);
    }

    public void info(String msg, Object... parameters) {
        if (factory.isInfoEnable()) itf.info(msg, parameters);
    }

    public void info(Throwable throwable, String msg) {
        if (factory.isInfoEnable()) itf.info(throwable, msg);
    }

    public void info(Throwable throwable, String msg, Object... parameters) {
        if (factory.isInfoEnable()) itf.info(throwable, msg, parameters);
    }

    public void warn(Object object) {
        if (factory.isWarnEnable()) itf.warn(object);
    }

    public void warn(Throwable throwable) {
        if (factory.isWarnEnable()) itf.warn(throwable);
    }

    public void warn(String msg, Object... parameters) {
        if (factory.isWarnEnable()) itf.warn(msg, parameters);
    }

    public void warn(Throwable throwable, String msg) {
        if (factory.isWarnEnable()) itf.warn(throwable, msg);
    }

    public void warn(Throwable throwable, String msg, Object... parameters) {
        if (factory.isWarnEnable()) itf.warn(throwable, msg, parameters);
    }

    public void imp(Object object) {
        if (factory.isImpEnable()) itf.imp(object);
    }

    public void imp(Throwable throwable) {
        if (factory.isImpEnable()) itf.imp(throwable);
    }

    public void imp(String msg, Object... parameters) {
        if (factory.isImpEnable()) itf.imp(msg, parameters);
    }

    public void imp(Throwable throwable, String msg) {
        if (factory.isImpEnable()) itf.imp(throwable, msg);
    }

    public void imp(Throwable throwable, String msg, Object... parameters) {
        if (factory.isImpEnable()) itf.imp(throwable, msg, parameters);
    }

    public void sql(Object object) {
        if (factory.isSqlEnable()) itf.sql(object);
    }

    public void sql(Throwable throwable) {
        if (factory.isSqlEnable()) itf.sql(throwable);
    }

    public void sql(String msg, Object... parameters) {
        if (factory.isSqlEnable()) itf.sql(msg, parameters);
    }

    public void sql(Throwable throwable, String msg) {
        if (factory.isSqlEnable()) itf.sql(throwable, msg);
    }

    public void sql(Throwable throwable, String msg, Object... parameters) {
        if (factory.isSqlEnable()) itf.sql(throwable, msg, parameters);
    }

    public void error(Object object) {
        if (factory.isErrorEnable()) itf.error(object);
    }

    public void error(Throwable throwable) {
        if (factory.isErrorEnable()) itf.error(throwable);
    }

    public void error(String msg, Object... parameters) {
        if (factory.isErrorEnable()) itf.error(msg, parameters);
    }

    public void error(Throwable throwable, String msg) {
        if (factory.isErrorEnable()) itf.error(throwable, msg);
    }

    public void error(Throwable throwable, String msg, Object... parameters) {
        if (factory.isErrorEnable()) itf.error(throwable, msg, parameters);
    }

    public void fatal(Object object) {
        if (factory.isFatalEnable()) itf.fatal(object);
    }

    public void fatal(Throwable throwable) {
        if (factory.isFatalEnable()) itf.fatal(throwable);
    }

    public void fatal(String msg, Object... parameters) {
        if (factory.isFatalEnable()) itf.fatal(msg, parameters);
    }

    public void fatal(Throwable throwable, String msg) {
        if (factory.isFatalEnable()) itf.fatal(throwable, msg);
    }

    public void fatal(Throwable throwable, String msg, Object... parameters) {
        if (factory.isFatalEnable()) itf.fatal(throwable, msg, parameters);
    }

    public void off(Object object) {
        if (factory.isOffEnable()) itf.off(object);
    }

    public void off(Throwable throwable) {
        if (factory.isOffEnable()) itf.off(throwable);
    }

    public void off(String msg, Object... parameters) {
        if (factory.isOffEnable()) itf.off(msg, parameters);
    }

    public void off(Throwable throwable, String msg) {
        if (factory.isOffEnable()) itf.off(throwable, msg);
    }

    public void off(Throwable throwable, String msg, Object... parameters) {
        if (factory.isOffEnable()) itf.off(throwable, msg, parameters);
    }

    public void log(JingLoggerLevelItf level, Object object) {
        if (factory.isLevelEnable(level)) itf.log(level, object);
    }

    public void log(JingLoggerLevelItf level, Throwable throwable) {
        if (factory.isLevelEnable(level)) itf.log(level, throwable);
    }

    public void log(JingLoggerLevelItf level, Throwable throwable, String msg) {
        if (factory.isLevelEnable(level)) itf.log(level, throwable, msg);
    }

    public void log(JingLoggerLevelItf level, Throwable throwable, String msg, Object... parameters) {
        if (factory.isLevelEnable(level)) itf.log(level, throwable, msg, parameters);
    }

    public void log(JingLoggerLevelItf level, String msg, Object... parameters) {
        if (factory.isLevelEnable(level)) itf.log(level, msg, parameters);
    }
}
